package com.braveman.im.ui.activity.message;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.braveman.im.R;
import com.braveman.im.bean.JoinBean;
import com.braveman.im.manager.ApiManager;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.UIUtils;
import com.vondear.rxtools.RxBarTool;

import retrofit2.Call;
import retrofit2.Response;

public class EditAddGroupforActivity extends BaseActivity {
    private EditText mEtActivityEditAddFriendsInfo;
    private String groupId;
    private String groupName;


    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("验证信息").setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtils.finishActivity(EditAddGroupforActivity.this);
            }
        });
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_edit_add_friends;
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        groupId = callIntent.getStringExtra("groupId");
        groupName = callIntent.getStringExtra("groupName");
    }

    @Override
    protected void initChildView() {
        mEtActivityEditAddFriendsInfo = (EditText) findViewById(R.id.et_activity_edit_add_friends_info);
    }

    @Override
    protected void initChildData() {

    }

    @Override
    protected void setChildViewListener() {
        findViewById(R.id.btn_activity_send).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_activity_send:
                JoinBean joinBean = new JoinBean();
                joinBean.groupId = groupId;
                joinBean.groupName = groupName;
                String verificationInformation = mEtActivityEditAddFriendsInfo.getText().toString().trim();
                if (TextUtils.isEmpty(verificationInformation)) {
                    UIUtils.showToast("申请信息不能为空，请填写申请信息");
                    return;
                }
                joinBean.verificationInformation = verificationInformation;
                showLoadingDialog();


                ApiManager.getApi().joinApplication(joinBean).enqueue(new NetCallBack<JoinBean>() {
                    @Override
                    protected void onSuccess(Call<JoinBean> call, Response<JoinBean> response) {
                        UIUtils.showToast("申请发送成功");
                        ActivityUtils.finishActivity(EditAddGroupforActivity.this);
                    }

                    @Override
                    protected void hiddenProgress() {
                        hideLodingDialog();
                    }
                });
                break;
        }
    }

}
